//
//  RBApplyAfterSalesVC.m
//  zhongzhenglu
//
//  Created by 马军凯 on 2023/5/6.
//

#import "RBApplyAfterSalesVC.h"
#import "RBUploadTool.h"
#import "RBScrollablePhotoContainer.h"


static NSInteger const maxCount = 3;

@interface RBApplyAfterSalesVC ()
<UITextViewDelegate>
//scrollView
@property (nonatomic, strong) UIScrollView *scrollView;
//
@property (nonatomic, strong) UIButton *submitBtn;
//
@property (nonatomic, strong) UITextView *markTV;
@property (nonatomic, strong) UILabel *placeholderLabel;


//图片上传工具
@property (nonatomic, strong) RBUploadTool *uploadTool;
//
@property (nonatomic, strong) RBScrollablePhotoContainer *photoView;

@end

@implementation RBApplyAfterSalesVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setup];
    [self setUI];
}
//
- (void)setup {
    self.title = @"线下售后";
    self.view.backgroundColor = [RBThemeConfig bgGrayColor];
}
//UI
- (void)setUI {
    [self submitBtn];
    [self scrollView];
    //
    UIView *reasonView = [self createReasonView];
    [self.scrollView addSubview:reasonView];
    [reasonView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(Zoom(12.5));
        make.right.mas_equalTo(-Zoom(12.5));
        make.top.mas_equalTo(self.scrollView.mas_top).offset(Zoom(10));
        make.height.mas_equalTo(60);
        make.width.mas_equalTo(Zoom(350));
    }];
    //
    UIView *markView = [self createMarkView];
    [self.scrollView addSubview:markView];
    [markView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(Zoom(12.5));
        make.right.mas_equalTo(-Zoom(12.5));
        make.top.mas_equalTo(reasonView.mas_bottom).offset(Zoom(10));
        make.width.mas_equalTo(Zoom(350));
    }];
    //
    UIView *photoView = [self createPhotoView];
    [self.scrollView addSubview:photoView];
    [photoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(Zoom(12.5));
        make.right.mas_equalTo(-Zoom(12.5));
        make.top.mas_equalTo(markView.mas_bottom).offset(Zoom(10));
        make.width.mas_equalTo(Zoom(350));
        make.bottom.mas_equalTo(self.scrollView.mas_bottom).offset(0);
    }];
}





#pragma mark UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView {
    if (textView.text.length == 0) {
        self.placeholderLabel.hidden = NO;
    } else {
        self.placeholderLabel.hidden = YES;
    }
}
#pragma mark 视图
//scrollView
- (UIScrollView *)scrollView {
    if (_scrollView == nil) {
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.showsVerticalScrollIndicator = NO;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.bounces = NO;
        _scrollView.backgroundColor = [RBThemeConfig bgGrayColor];
        [self.view addSubview:_scrollView];
        [_scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.mas_equalTo(0);
            make.width.mas_equalTo(SCREEN_WIDTH);
            make.bottom.mas_equalTo(self.submitBtn.mas_top).offset(-20);
        }];
    }
    return _scrollView;
}
//售后原因
- (UIView *)createReasonView {
    UIView *view = UIView.new;
    view.backgroundColor = [UIColor whiteColor];
    [view rbSetCornerRadius:8];
    
    UILabel *titleLabel = [UILabel new];
    titleLabel.text = @"售后原因";
    titleLabel.textColor = [UIColor LC_hex:@"#333333"];
    titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    [view addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(view.mas_left).offset(15);
        make.centerY.mas_equalTo(view);
    }];
    //原因
    UITextField *reasonTF = UITextField.new;
    reasonTF.placeholder = @"请选择退款原因";
    reasonTF.textColor = [UIColor LC_hex:@"#202224"];
    reasonTF.enabled = NO;
    reasonTF.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    reasonTF.textAlignment = NSTextAlignmentRight;
    [view addSubview:reasonTF];
    [reasonTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(titleLabel.mas_right).offset(10);
        make.height.mas_equalTo(30);
        make.centerY.mas_equalTo(view);
    }];
    [reasonTF setContentHuggingPriority:249 forAxis:UILayoutConstraintAxisHorizontal];
    
    
    //箭头
    UIImageView *arrowImageView = [UIImageView new];
    arrowImageView.image = [UIImage imageNamed:@"mine_arrow_right"];
    [view addSubview:arrowImageView];
    [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(reasonTF.mas_right).offset(10);
        make.right.mas_equalTo(view.mas_right).offset(-10);
        make.centerY.mas_equalTo(view);
        make.width.mas_equalTo(7.5);
        make.height.mas_equalTo(13.5);
    }];
    
    return view;
}
//问题描述
- (UIView *)createMarkView {
    UIView *markView = UIView.new;
    markView.backgroundColor = [UIColor whiteColor];
    [markView rbSetCornerRadius:8];
    
    UILabel *titleLabel = UILabel.new;
    titleLabel.text = @"售后问题描述";
    titleLabel.textColor = [UIColor LC_hex:@"#333333"];
    titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    [markView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(markView.mas_top).offset(25);
        make.left.mas_equalTo(markView.mas_left).offset(15);
        make.right.mas_equalTo(markView.mas_right).offset(-15);
    }];
    
    self.markTV = [[UITextView alloc] init];
    self.markTV.font = [UIFont systemFontOfSize:14];
    self.markTV.textColor = [UIColor LC_hex:@"#202224"];
    self.markTV.delegate = self;
    [markView addSubview:self.markTV];
    [self.markTV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(10);
        make.left.mas_equalTo(markView.mas_left).offset(10);
        make.right.mas_equalTo(markView.mas_right).offset(-10);
        make.bottom.mas_equalTo(markView.mas_bottom).offset(-20);
        make.height.mas_equalTo(Zoom(50));
    }];
    
    self.placeholderLabel = UILabel.new;
    self.placeholderLabel.text = @"请填写详细描述，我们会尽快为您解决";
    self.placeholderLabel.textColor = [UIColor LC_hex:@"#A2A2A2"];
    self.placeholderLabel.font = [UIFont systemFontOfSize:14];
    [self.markTV addSubview:self.placeholderLabel];
    [self.placeholderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.markTV.mas_left).offset(5);
        make.right.mas_equalTo(self.markTV.mas_right).offset(-5);
        make.top.mas_equalTo(self.markTV.mas_top).offset(8);
    }];
    
    return markView;
}
//补充照片
- (UIView *)createPhotoView {
    UIView *photoView = UIView.new;
    [photoView rbSetCornerRadius:8];
    photoView.backgroundColor = [UIColor whiteColor];
    
    UILabel *titleLabel = UILabel.new;
    titleLabel.text = @"补充照片";
    titleLabel.textColor = [UIColor LC_hex:@"#333333"];
    titleLabel.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
    [photoView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(photoView.mas_top).offset(25);
        make.left.mas_equalTo(photoView.mas_left).offset(15);
        make.right.mas_equalTo(photoView.mas_right).offset(-15);
    }];
    
    RBScrollablePhotoContainer *view = [RBScrollablePhotoContainer viewWithMaxNum:maxCount itemWidth:Zoom(78) itemHeight:Zoom(78) itemPadding:Zoom(10) editable:YES];
    self.photoView = view;
    //collectionView
    [photoView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(photoView.mas_left).offset(Zoom(15));
        make.right.mas_equalTo(photoView.mas_right).offset(-Zoom(15));
        make.height.mas_equalTo(Zoom(78));
        make.top.mas_equalTo(titleLabel.mas_bottom).offset(20);
        make.bottom.mas_equalTo(photoView.mas_bottom).offset(-20);
    }];
    
    return photoView;
}
//按钮
- (UIButton *)submitBtn {
    if (_submitBtn == nil) {
        _submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_submitBtn setTitle:@"立即提交" forState:UIControlStateNormal];
        _submitBtn.backgroundColor = [UIColor LC_hex:@"#518CFF"];
        [_submitBtn rbSetCornerRadius:Zoom(22.5)];
        _submitBtn.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
        [self.view addSubview:_submitBtn];
        [_submitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.view);
            make.bottom.mas_equalTo(self.view.mas_bottom).offset(-TAB_BAR_SAFE_MARGIN - 30);
            make.width.mas_equalTo(Zoom(340));
            make.height.mas_equalTo(Zoom(45));
        }];
    }
    return _submitBtn;
}




//上传图片的工具
- (RBUploadTool *)uploadTool {
    if (!_uploadTool) {
        self.uploadTool = RBUploadTool.new;
    }
    return _uploadTool;
}

@end
